package com.njuse.jvmfinal.Instruction;

import java.nio.ByteBuffer;

import com.njuse.jvmfinal.runtimestructure.Jframe;

public class DCMPL extends Instruction {
	public  void readindex(ByteBuffer reader) {
		//no need to read
	}
	
	public  void execute(Jframe frame) {
		int top=frame.getStacktop();
		Object[] stack=frame.getManagestack();
        Object temp2hi=stack[top-1];
        Object temp2lo=stack[top-2];
        Object temp1hi=stack[top-3];
        Object temp1lo=stack[top-4];
        top=top-4;
        try {
        	int temp1high=(int)temp1hi;
        	int temp1low=(int)temp1lo;
        	int temp2high=(int)temp2hi;
        	int temp2low=(int)temp2lo;
        	long temp1=(((long) temp1high) << 32) | ((long) temp1low & 0x0ffffffffL);
        	long temp2=(((long) temp2high) << 32) | ((long) temp2low & 0x0ffffffffL);
        	double value1=Double.longBitsToDouble(temp1);
        	double value2=Double.longBitsToDouble(temp2);
        	if (value1>value2) {
        		stack[top]=1;
        	}else if (value1==value2){
        		stack[top]=0;
        	}else {
        		stack[top]=-1;
        	}
        	top++;
        	frame.setManagestack(stack);
        	frame.setStacktop(top);
        }catch(Exception e) {
        	stack[top]=-1;
        	top++;
        	frame.setManagestack(stack);
        	frame.setStacktop(top);
        }
	}
}
